package com.browsesoft.user;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.htmlcomponent.HTMLFormModel;

/**
 * 用户提示表单model
 */
public class UserTipModel implements HTMLFormModel {
	/**
	 * 初始化model
	 * 
	 * @throws Exception
	 */
	public void init(HttpServletRequest request) throws Exception {
	}

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		User user = (User) request.getSession().getAttribute("loginUser");
		String isTip = request.getParameter("istip");
		String tipTime = request.getParameter("tiptime");
		String isshutdown = request.getParameter("isshutdown");
		if (isshutdown != null) {
			if (user.getIsTip()) {
				user.setIsTip(false);
				user.update();
			}
		} else {
			if (isTip != null && !tipTime.equals("")) {
				user.setIsTip(true);
				user.setTiptime(Integer.parseInt(tipTime) * 60);
			}
		}
	}

	/**
	 * 更新属性
	 * 
	 * @param ht
	 *            存储属性的哈息表
	 */
	public void updateAttributes(Hashtable ht) throws Exception {
	}

	/**
	 * 得到属性
	 * 
	 * @return 存储属性的哈息表
	 */
	public Hashtable getAttributes() throws Exception {
		return new Hashtable();
	}

	/**
	 * 得到选择列表
	 * 
	 * @param name
	 *            名字
	 * @return 列表
	 */
	public Iterator getOptions(String name) throws Exception {
		LinkedList v = new LinkedList();
		return v.iterator();
	}

	public void setComponent(HTMLBasicComponent component) {
	}

	/**
	 * 模型更新页面元素
	 * 
	 * @throws Exception
	 */
	public void updatePageElement(HTMLBasicComponent c) throws Exception {
	}
}